import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(
          useMaterial3: false,
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: const Text("Flutter App"),
          ),
          body: const MyHome(),
        ));
  }
}

class MyHome extends StatefulWidget {
  const MyHome({super.key});

  @override
  State<MyHome> createState() => _MyHomeState();
}

class _MyHomeState extends State<MyHome> {

  int _currentIndex = 0;

  List<Widget> images = [
    const Image(image: NetworkImage("https://www.itying.com/images/flutter/1.png"), fit: BoxFit.cover,),
    const Image(image: NetworkImage("https://www.itying.com/images/flutter/2.png"), fit: BoxFit.cover,),
    const Image(image: NetworkImage("https://www.itying.com/images/flutter/3.png"), fit: BoxFit.cover,),
  ];

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 200,
      child: Stack(
        children: [
          PageView.builder(
            scrollDirection: Axis.horizontal,
            itemCount: 10000,
            itemBuilder: (context, index) {
              return images[index % images.length];
            },
            onPageChanged: (index){
              setState(() {
                _currentIndex=index % images.length;
              });
            },
          ),
          Positioned(
              left: 0,
              right: 0,
              bottom: 2,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: List.generate(3, (index) {
                  return Container(
                    height: 10,
                    width: 10,
                    margin: const EdgeInsets.all(5),
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      color: _currentIndex == index ? Colors.blue : Colors.grey,
                    ),
                  );
                }),
              )),
        ],
      ),
    );
  }
}
